package org.example;
import java.util.Random;

public class CalculationSystem_V02 {
    static class Question {
        int a;
        int b;
        char op;
        int answer;

        Question(int a, int b, char op, int answer) {
            this.a = a;
            this.b = b;
            this.op = op;
            this.answer = answer;
        }
    }

    public static void main(String[] args) {
        Random random = new Random();
        Question[] questions = new Question[50];

        // 生成题目（保证加法和≤100，减法差≥0）
        for (int i = 0; i < 50; i++) {
            char op = random.nextBoolean() ? '+' : '-';
            int a, b, ans;
            if (op == '+') {
                a = random.nextInt(100) + 1;
                b = random.nextInt(101 - a); // 保证a+b ≤100
                ans = a + b;
            } else {
                a = random.nextInt(100) + 1;
                b = random.nextInt(a) + 1; // 保证a - b ≥0
                ans = a - b;
            }
            questions[i] = new Question(a, b, op, ans);
        }

        // 格式化输出（每行4题）
        System.out.println("加减法口算练习系统-v0.2");
        for (int i = 0; i < 50; i++) {
            Question q = questions[i];
            System.out.printf("%d %c %d = %d\t", q.a, q.op, q.b, q.answer);
            if ((i + 1) % 4 == 0) System.out.println(); // 每4题换行
        }
    }
}